package cn.jdy.platform.tag;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import cn.jdy.framework.util.SpringContextUtils;
import cn.jdy.plugins.entity.Product;
import cn.jdy.plugins.service.ProductService;

/**
 * 产品类型的自定义标签
 * @description 将产品这种常规性的功能通过自定义标签后获取内容
 * @author zhaigt
 * @date 2015年6月26日
 */
public class ProductListTag extends SimpleTagSupport implements java.io.Serializable{
	private static final long serialVersionUID = 1L;
	private String var;
	private boolean pid=false;// 父栏目id
	private Long columnid;// 栏目id
	private int limitMax=50; //默认一次最多查询记录数
	private String style;// 显示样式
	
	private boolean img=false;// 是否过滤封面图片

	@Override
	public void doTag() throws JspException, IOException {
	  ProductService productService = SpringContextUtils.getBean(ProductService.class);
	  
		List<Product> list = null;
		if(pid){// 按照父分类查询
		  list = productService.findbyPid(columnid, 0, limitMax, img);
		}else{// 按照栏目查询
		  list = productService.findbytype(columnid, 0, limitMax, img);
		}
		
		Iterator<Product> ite = list.iterator();
		// 进行迭代
		while (ite.hasNext()) {
			Object obj = ite.next();
			getJspContext().setAttribute(var, obj);
			//输出标签体
			getJspBody().invoke(null);
		}
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}
	


  public int getLimitMax() {
    return limitMax;
  }

  public void setLimitMax(int limitMax) {
    this.limitMax = limitMax;
  }

  public Long getColumnid() {
    return columnid;
  }

  public void setColumnid(Long columnid) {
    this.columnid = columnid;
  }

  public boolean getPid() {
    return pid;
  }

  public void setPid(boolean pid) {
    this.pid = pid;
  }

  public boolean getImg() {
    return img;
  }

  public void setImg(boolean img) {
    this.img = img;
  }
 


}
